<?php
declare(strict_types=1);
namespace SixShop\Payment\Model;

use SixShop\Payment\Enum\NumberBizEnum;
use SixShop\Payment\Enum\PaymentBizEnum;
use SixShop\Payment\Enum\PaymentStatusEnum;
use think\Model;

/**
 * Class SixShop\Payment\Model\ExtensionPaymentModel
 *
 * @property \SixShop\Payment\Enum\PaymentBizEnum $biz_type 业务类型：1-商品订单支付
 * @property \SixShop\Payment\Enum\PaymentStatusEnum $status 支付状态：0-待支付/1-支付中/2-成功/3-失败/4-已关闭/5-退款中
 * @property array $payment_param 支付参数
 * @property array $payment_result 查询支付结果信息
 * @property float $amount 支付金额（元）
 * @property int $expire_time 订单失效时间
 * @property int $id
 * @property int $order_id 关联订单ID
 * @property int $payment_time 支付成功时间
 * @property int $user_id 用户ID
 * @property string $create_time
 * @property string $order_sn 订单编号
 * @property string $out_trade_no 商户支付订单号
 * @property string $pay_type 支付方式：wechatpay-微信 xlpayment-信联支付
 * @property string $status_desc 支付状态说明
 * @property string $transaction_id 三方支付订单号
 * @property string $update_time
 */
class ExtensionPaymentModel extends Model
{
    protected $name = 'extension_payment';
    protected $pk = 'id';

    protected array $type = [
        'biz_type' => PaymentBizEnum::class,
        'status' => PaymentStatusEnum::class,
        'amount' => 'float',
        'payment_param' => 'json',
        'payment_result' => 'json',
    ];
    protected function setOutTradeNoAttr($value, $data): string
    {
        return generate_number(NumberBizEnum::fromPaymentBiz($data['biz_type']));
    }

    protected function getOptions(): array
    {
        return [
            'insert' => ['out_trade_no'],
            'readonly' => ['order_id', 'order_sn', 'out_trade_no', 'biz_type', 'pay_type', 'amount'],
        ];
    }
}